package com.bkq.cb.BLO;

import com.bkq.cb.GetDMY;
import com.bkq.cb.SqliteServices;

import android.content.Context;
import android.database.Cursor;

public class ReturnDayReport {
	
	 private static Cursor mCursor;
	 private static SqliteServices service = null;
	 GetDMY g = new GetDMY();
	 public ReturnDayReport(Context context)
		{
			service = new SqliteServices(context);
		}
	 public float[] getValue(String today,String idUser)
	 {
		 float[]s=new float[6]; 
			s[0] =0;
			s[1] =0;
			s[2] =0;
			s[3]=0;
			s[4]=0;
			s[5]=0;
	//String y = g.getYear(today);
	//int m = Integer.parseInt(g.getMonth(today));
	
	service.openDatabase();
		mCursor = service.queryData("select * from tblTransaction");
		if(mCursor.moveToFirst())
		{
			if(mCursor.getString(3).equals(today)&&mCursor.getString(1).equals(idUser))
			{
				if(mCursor.getString(5).equals("income"))
					s[0]+=Float.parseFloat(mCursor.getString(4).toString());
				else s[1]+=Float.parseFloat(mCursor.getString(4).toString());
			}
			while(mCursor.moveToNext())
			{
				if(mCursor.getString(3).equals(today)&&mCursor.getString(1).equals(idUser))
				{
					if(mCursor.getString(5).equals("income"))
						s[0]+=Float.parseFloat(mCursor.getString(4).toString());
					else s[1]+=Float.parseFloat(mCursor.getString(4).toString());
				}
			}
		}
		mCursor = service.queryData("select * from tblLoan");
		if(mCursor.moveToFirst())
		{
			if(mCursor.getString(3).equals(today)&&mCursor.getString(1).equals(idUser))
			{
				if(mCursor.getString(6).equals("Lend"))
					s[3]+=Float.parseFloat(mCursor.getString(5).toString());
				else s[4]+=Float.parseFloat(mCursor.getString(5).toString());
			}
			while(mCursor.moveToNext())
			{
				if(mCursor.getString(3).equals(today)&&mCursor.getString(1).equals(idUser))
				{
					if(mCursor.getString(6).equals("Lend"))
						s[3]+=Float.parseFloat(mCursor.getString(5).toString());
					else s[4]+=Float.parseFloat(mCursor.getString(5).toString());
				}
			}
		}
		s[2] = s[0] - s[1];		
		s[5]=s[3]-s[4];
		mCursor.close();
		service.close();
		return s;
		
	 }
}
